<template>
  <div class="wrapper">
     <img class="img" src="../../assets/logos.png" alt="">
    <van-form @submit="onSubmit">
      <van-field
        v-model="register.mobile"
        type="text"
        name="手机号"
        placeholder="请输入手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
      <van-field
        v-model="register.sms_code"
        center
        clearable
        placeholder="请输入验证码"
      >
        <template #button>
          <span
            v-show="sendAuthCode"
            class="auth_text auth_text_blue"
            @click="getAuthCode"
            >获取验证码</span
          >
          <span v-show="!sendAuthCode" class="auth_text">
            <span class="auth_text_blue">{{ auth_time }} </span>
            秒之后重新发送验证码</span
          >
        </template>
      </van-field>
      <div class="lz_login_txt">
        <span>*未注册的手机号将自动注册</span>
        <router-link to="/login" tap="span">使用密码登录</router-link>
      </div>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">
          登录
        </van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { lzGetSMS, lzlogin } from "../../utils/http";
export default {
  name: "",
  components: {},
  props: [],
  data() {
    return {
      register: {
        mobile: "19801237380",
        sms_code: "",
        sms_type: "login",
        type: 2,
        client: 1,
      },
      sendAuthCode: true,
      auth_time: 0,
      
    };
  },
  mounted() {},
  methods: {
    async onSubmit(values) {
      const res = await lzlogin(this.register);
      console.log(res);
      sessionStorage.setItem('userInfo',JSON.stringify(res))
          this.$router.push({
          path: '/mine'
        })
    },
    async getAuthCode() {
      //发送验证码
      console.log(this.register.sms_code)
      const res = await lzGetSMS(this.register);
      console.log(res);
   
      //验证码倒计时
      this.sendAuthCode = false;
      this.auth_time = 30;
      var auth_timetimer = setInterval(() => {
        this.auth_time--;
        if (this.auth_time <= 0) {
          this.sendAuthCode = true;
          clearInterval(auth_timetimer);
        }
      }, 1000);
    },
  },
  computed: {},
  watch: {},
  created() {},
};
</script>

<style scoped>
.wrapper{
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items:center;
}
.form{
    width: 80%;
}
.van-field{
    border-bottom: 1px solid #ccc;
}

.lz_zhuce{
  display: flex;
  justify-content: space-between;
  color:#ccc;
  margin-top: 10px;
}
.router-link{
  color:#ccc;
}
.van-button{
  background: #FF8247;
  border:none;
}
.img{
  width: 80%;
  margin: 13.3333vw auto;
}
.lz_login_txt{
  color:#ccc;
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
}
</style>
